//
//  LPTMedicineCountTableViewCell.m
//  LPTClient
//
//  Created by mac on 2018/12/15.
//  Copyright © 2018年 zhaodd. All rights reserved.
//

#import "LPTMedicineCountTableViewCell.h"

@interface LPTMedicineCountTableViewCell ()

@property (weak, nonatomic) IBOutlet UILabel *medicineNameLab;
@property (weak, nonatomic) IBOutlet UIButton *minusBtn;
@property (weak, nonatomic) IBOutlet UILabel *numLabel;
@property (weak, nonatomic) IBOutlet UIButton *addBtn;
@property (weak, nonatomic) IBOutlet UILabel *medCountLabel;
@property (weak, nonatomic) IBOutlet UIButton *deleteBtn;
@property (strong, nonatomic)LPTMediModel *model;

@end

@implementation LPTMedicineCountTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(void)refreshWithEntity:(LPTMediModel *)model
{
    self.model = model;
    self.medicineNameLab.text = model.chinese_medicine.name;
    self.medCountLabel.text = [NSString stringWithFormat:@"%zdg",model.weight];
    self.numLabel.text = [NSString stringWithFormat:@"%zd",model.weight];
}

-(void)setEdit:(BOOL)edit
{
    _edit = edit;
    
    if (edit) {
        self.medCountLabel.hidden = YES;
        self.minusBtn.hidden = NO;
        self.numLabel.hidden = NO;
        self.addBtn.hidden = NO;
        self.deleteBtn.hidden = NO;
    }else{
        self.medCountLabel.hidden = NO;
        self.minusBtn.hidden = YES;
        self.numLabel.hidden = YES;
        self.addBtn.hidden = YES;
        self.deleteBtn.hidden = YES;
    }
}

- (IBAction)minusAction:(id)sender {
    
    if (self.model.weight > 1) {
        self.model.weight -- ;
    }
    
    [self refreshWithEntity:self.model];
}

- (IBAction)addAction:(id)sender {
    
    self.model.weight ++;
    [self refreshWithEntity:self.model];
}

- (IBAction)deleteAction:(id)sender {
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(medicineCountTableViewCell:didDeleteModel:)]) {
        [self.delegate medicineCountTableViewCell:self didDeleteModel:self.model];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
